﻿using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Mota.XMLControls
{
    /// <summary>
    /// Represent Numeric control based on DX TrackBarControl 
    /// </summary>
    public class DXGuiRangeTrackBar:GuiRangeTrackBar
    {
        public DXGuiRangeTrackBar()
        {

            visualControl = new MyDxRangeTrackBar();
            (visualControl as MyDxRangeTrackBar).ShowToolTips = true;
            (visualControl as MyDxRangeTrackBar).Properties.ShowValueToolTip = true;
            (visualControl as MyDxRangeTrackBar).EditValueChanged += DXGuiRangeTrackBar_EditValueChanged;
        }

        void DXGuiRangeTrackBar_EditValueChanged(object sender, System.EventArgs e)
        {
            var binding = (sender as MyDxRangeTrackBar).DataBindings["XmlItems"];
            if (binding != null)
                binding.WriteValue();
        }
        public override string Text
        {
            get
            {
                return (visualControl as MyDxRangeTrackBar).Text;
            }
            set
            {
                (visualControl as MyDxRangeTrackBar).Text = value;
            }
        }


        public override int Step
        {
            get
            {
                return (visualControl as MyDxRangeTrackBar).Properties.TickFrequency;
            }
            set
            {
                (visualControl as MyDxRangeTrackBar).Properties.TickFrequency = value;
            }
        }


        public override int Min
        {
            get
            {
                return (visualControl as MyDxRangeTrackBar).Properties.Minimum;
            }
            set
            {
                (visualControl as MyDxRangeTrackBar).Properties.Minimum = value;
            }
        }
        public override int Max
        {
            get
            {
                return (visualControl as MyDxRangeTrackBar).Properties.Maximum;
            }
            set
            {
                (visualControl as MyDxRangeTrackBar).Properties.Maximum = value;
            }
        }
        public override void SetValue(object valueBinding)
        {
            if(valueBinding is BindingSource)
                (visualControl as MyDxRangeTrackBar).DataBindings.Add("XmlItems", valueBinding as BindingSource, XmlAttributes["XMLAttribute"], true);

        }
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
               // throw new System.NotImplementedException();
            }
        }

        public override object GetValue()
        {
            return (this.visualControl as MyDxRangeTrackBar).XmlItems;
        }
    }
}
